// cloudfunctionRoot/payNotify/index.js
const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
const db = cloud.database()

// 支付回调处理
exports.main = async (event, context) => {
    console.log('回调',event);
  try {
    // 解析支付结果
    const { goodsId } = event
    const goodsUpdateResult = await db.collection('blindbox_goods').doc(goodsId).update({
        data: {
          status: false, // 设置为已售出状态
          soldTime: db.serverDate()
        }
      })
    
    return goodsUpdateResult
  } catch (error) {
    console.error('处理支付回调失败:', error)
    return { success: false, message: error.message || '处理支付回调失败' }
  }
}